import {
  initIdb, initIndexDB, compositeQuerySingleIndexDB
} from "@/utils/util.js"

const getDefaultState = () => {
  return {
    db:{},
    idb:{}
  }
}

const state = getDefaultState()
const mutations = {
  SET_DB:(state, val) => {
    state.db = val;
  },
  SET_IDB:(state, val) => {
    state.idb = val;
  },
}
const actions = {
  setDb({ commit }){
    return new Promise((resolve, reject) => {
      initIndexDB('tools').then(res => {
        commit('SET_DB',res)
        resolve(res)
      })
      
    })
  },
  setIdb({ commit }){
    return new Promise((resolve, reject) => {
      initIdb().then(res => {
        commit('SET_IDB',res)
        resolve(res)
      })
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}